/*
  类型断言：
    绕过TS编译检查，类型断言就是对编译器说：我就是这个类型，无需检查
*/
class Vechile {
  static count: number = 3;
  public brand: string; // 品牌
  public vechildNo: string; // 车牌号
  public days: number; // 租聘天数
  public total: number = 0; // 支付的租聘总费用
  constructor(brand_: string, vechildNo_: string, days_: number) {
    this.brand = brand_;
    this.vechildNo = vechildNo_;
    this.days = days_;
  }

  public calculateRent() {
    console.log(this.brand + "车牌号为：" + this.vechildNo + "开始被租");
    return 0;
  }
}

class Car extends Vechile {
  public type: string; // 车的型号
  constructor(
    brand_: string,
    vechildNo_: string,
    days_: number,
    type_: string
  ) {
    super(brand_, vechildNo_, days_);
    this.type = type_;
  }

  // 根据车的型号来获取租用一天该型号车的组件
  public getPriceByType() {
    let rentMoneyByDay: number = 0; // 每天的租金
    if (this.type === "普拉多巡洋舰") {
      rentMoneyByDay = 800;
    } else if (this.type === "凯美瑞旗舰版") {
      rentMoneyByDay = 400;
    } else if (this.type === "威驰智行版") {
      rentMoneyByDay = 200;
    }
    return rentMoneyByDay;
  }

  public calculateRent(): number {
    super.calculateRent();
    console.log("小轿车被组。。。。");
    return this.days * this.getPriceByType();
  }
}

class Bus extends Vechile {
  public seatNum: number; // 车的型号
  constructor(
    brand_: string,
    vechildNo_: string,
    days_: number,
    seatNum_: number
  ) {
    super(brand_, vechildNo_, days_);
    this.seatNum = seatNum_;
  }

  // 根据车的型号来获取租用一天该型号车的组件
  public getPriceByType() {
    let rentMoneyByDay: number = 0; // 每天的租金
    if (this.seatNum <= 16) {
      rentMoneyByDay = 800;
    } else if (this.seatNum >= 16) {
      rentMoneyByDay = 1600;
    }
    return rentMoneyByDay;
  }

  public calculateRent(): number {
    super.calculateRent();
    console.log("小轿车被组。。。。");
    return this.days * this.getPriceByType();
  }
}

class Truck extends Vechile {
  public ton: number; // 车的型号
  constructor(brand_: string, vechildNo_: string, days_: number, ton_: number) {
    super(brand_, vechildNo_, days_);
    this.ton = ton_;
  }

  // 根据车的型号来获取租用一天该型号车的组件
  public getPriceByType() {
    let rentMoneyByDay: number = 0; // 每天的租金
    if (this.ton <= 500) {
      rentMoneyByDay = 750;
    } else if (this.ton >= 500) {
      rentMoneyByDay = 1350;
    }
    return rentMoneyByDay;
  }

  public calculateRent(): number {
    super.calculateRent();
    console.log("小轿车被组。。。。");
    return this.days * this.getPriceByType();
  }
}

class Custtomer {
  rent(vechild: Vechile) {
    let car = vechild as Car;
    console.log(car.type);
    return vechild.calculateRent();
  }
}

let cust: Custtomer = new Custtomer();
let car = new Car("普拉多巡洋舰", "110", 3, "普拉多巡洋舰");
console.log(cust.rent(car));

// let truck: Truck = new Truck("AA", "110", 3, 300);
let vechile: Vechile = new Car("普拉多巡洋舰", "110", 3, "普拉多巡洋舰");
vechile = new Truck("AA", "110", 3, 300);
let car1: Car = vechile as Car;
console.log(car1.getPriceByType());

export {};
